<template>
  <div>
    <div class="mod-config">
      <el-form>
        <el-form-item :inline="true">
          <el-button type="primary" @click="addOrUpdateHandle()" @refreshDataList="getDataList">新增</el-button>
          <!--          <el-button v-if="isAuth('sys:user:delete')" type="danger" @click="delOrUpdateHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>-->
        </el-form-item>
      </el-form>
      <el-table :data="dataList" border v-loading="dataListLoading" style="width: 100%;">
        <el-table-column align="center" type="index" header-align="center" width="80px" label="ID"></el-table-column>
        <el-table-column align="center" prop="moduleName" header-align="center" label="模块名称"></el-table-column>
        <el-table-column align="center" prop="redirectUrl" header-align="center" label="模块地址"></el-table-column>
        <el-table-column label="排序" align="center" width="150">
          <template slot-scope="scope">
            <span>{{scope.row.sort}}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="createTime" header-align="center" label="创建时间"></el-table-column>
        <el-table-column align="center" prop="updateTime" header-align="center" label="更新时间"></el-table-column>
        <el-table-column header-align="center" align="center" label="操作">
          <template slot-scope="scope">
            <el-button type="text" @click="addOrUpdateHandle(scope.row.id)">编辑</el-button>
            <el-button type="text" @click="delOrUpdateHandle(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--      新增-->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </div>
  </div>
</template>

<script>
import AddOrUpdate from './adskipper-add'

export default {
  name: 'advertisement',
  data() {
    return {
      addOrUpdateVisible: false,
      dataListLoading: false,
      dataList: [],
      actionUrl: '',
      fileList: []
    }
  },
  components: {
    AddOrUpdate
  },
  mounted() {
    this.getDataList()
  },
  methods: {
    getDataList() {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/news-admin/redirecturl/list'),
        method: 'post',
        data: {
          page: this.pageIndex,
          limit: this.pageSize
        }
      }).then(({ data }) => {
        if (data) {
          this.dataList = data.list
          this.totalPage = data.totalCount
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataList()
    },
    // selectionChangeHandle (val) {
    //   this.dataListSelections = val
    // },
    addOrUpdateHandle(id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    },
    delOrUpdateHandle(id) {
      var ids = id ? [id] : this.dataListSelections.map(item => item.id)
      this.$confirm(
        // `确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`,
        `确定要进行删除操作吗？`,
        '提示',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(() => {
        let dataForm = new FormData()
        dataForm.append('ids', ids)
        this.$http({
          url: this.$http.adornUrl('/news-admin/redirecturl/delete'),
          method: 'post',
          data: dataForm
        }).then(data => {
          if (data && data.code === 200) {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500
            })
            this.getDataList()
          } else {
            this.$message.warning(data.msg)
          }
        })
      })
    }
  }
}
</script>

<style scoped>
</style>
